# See LICENSE for licensing information.
PROJECT = streetlight
VERSION=0.1.0
# DIALYZER = dialyzer
CHMOD = $(shell chmod a+x ./rebar3)
REBAR = ./rebar3

.PHONY: deps build version release console doc clean distclean#dialyze test

all: clean build

deps:
	@$(CHMOD)
	@$(REBAR) get-deps

build:
	@$(CHMOD)
	@$(REBAR) compile

version:
	@echo "Setting version:$(VERSION)"
	@perl -p -i -e "s/^\s*{vsn,.*/  {vsn, \"$(VERSION)\"},/g" src/${PROJECT}.app.src
	@perl -p -i -e "s/^{relx,.*/{relx, [{release, {${PROJECT} , \"$(VERSION)\"},/g" rebar.config
	@echo "Done"

upgrade:
	@$(CHMOD)
	@$(REBAR) upgrade

release:
	@$(CHMOD)
	@$(REBAR) release

console:
	./_build/default/rel/${PROJECT}/bin/${PROJECT} console

doc:
	@$(CHMOD)
	@$(REBAR) edoc

clean:
	@$(CHMOD)
	@$(REBAR) clean

distclean: clean
	@$(REBAR) delete-deps

.PHONY: pack relup test

pack:
	@$(CHMOD)
	@rm -rf ${PROJECT} && rm -rf _build/${VERSION} && rm -rf _build/default/lib/${PROJECT}
	@$(REBAR) as ${VERSION} tar

relup:
	@$(CHMOD)
	@$(REBAR) relup -n ${PROJECT} -v ${VERSION} tar

test:
	@$(CHMOD)
	@$(REBAR) ct
	@$(REBAR) eunit

# .elora_dialyzer.plt:
# 	@$(DIALYZER) --build_plt --output_plt .elora_dialyzer.plt \
# 		--apps erts kernel stdlib crypto

# dialyze: .elora_dialyzer.plt
# 	@$(DIALYZER) --src src --plt .elora_dialyzer.plt --no_native \
# 		-Wunmatched_returns -Werror_handling -Wrace_conditions

